package org.jsola.hr.exception;

import lombok.extern.slf4j.Slf4j;
import org.jsola.autoconfigure.error.BaseExceptionTranslator;
import org.jsola.core.Result;
import org.jsola.exception.ParamException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 处理easyExcel抛出的异常
 *
 * @author wcl
 */
@Slf4j
@ControllerAdvice
@Order(Ordered.LOWEST_PRECEDENCE - 200)
public class EasyExcelExceptionTranslator extends BaseExceptionTranslator {


    @ExceptionHandler(com.alibaba.excel.exception.ExcelAnalysisException.class)
    @ResponseStatus(HttpStatus.OK)
    @ResponseBody
    public Result excelException(ParamException ex) {
        return ex.getErrorResult();
    }

}
